Welcome Guest | Sign in | Register

Home > Java Programming > Final and Datatypes > Questions and Answers

01.  Public class Manager{
Static final String name;
Public static void main(String args[]){
System.out.println(name.length()); }
}
A. 0 B. null
C. compile time error D. runtime error

Answer and Explanation

Answer: compile time error

Explanation:
final variable should be initialized , here without initializing they are trying to access the value of name variable so it will throw compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. Public class Manager{
Static final String name;
Static{
name=”lara”;
}
Public static void main(String args[]){
System.out.println(name.length()); } }
A. 0 B. null
C. compile time error D. 4

Answer and Explanation

Answer: 4

Explanation:
final variable is initialized in a static block. So it will not throw any error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Public class Manager{
Static final String name=”init”;
Static{
name=”lara”;
}
Public static void main(String args[]){
System.out.println(name.length()); } }
A. 0 B. null
C. compile time error D. 4

Answer and Explanation

Answer: 4

Explanation:
Final variable value is fixed. Here while declare a variable they have initialized , and inside a static variable also they have initialized. Therefore two times they can’t initialize a same final variable if so it will throw an compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Public class Manager{
Static final int all[]=new int[]{0};
Public static void main(String args[]){
System.out.println(all.length); } }
A. 0 B. null
C. compile time error D. 1

Answer and Explanation

Answer: 1

Explanation:
Explanation:it is a normal flow of execution

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. Class Manager{
Public static void main(String args[]){
Double d=test(100);
System.out.println(“done”);
}
Static long test(float f){
return f; }
}
A. 100 B. done
C. compile time error D. runtime error

Answer and Explanation

Answer: compile time error

Explanation:

From main method() we are calling test() method by passing 100, but in a called function it is accepting of type float so it will throw compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. class A{
Public static void main(String args[]){
String s1=Float.toString(5.55);
System.out.println(s1);
} }
A. 5.55 B. null
C. compile time error D. runtime error

Answer and Explanation

Answer: compile time error

Explanation:
we can not convert float to String . if you try it will throw compile error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. Class Test1{
Public static void main(String args[]){
Integer i1=10;
Integer i2=10;
If(i1==i2){
System.out.println(“ same”); }
Else{
System.out.println(“not same”) ; }
If(i1.equals(i2)){
System.out.println(“meaning fully equal”) ;}
} }
A. same not same meaning fully equal B.
same meaning fully equal not same     
C. same meaning fully equal   D.
not same

Answer and Explanation

Answer: same meaning fully equal  

Explanation:
here i1 and i2 are not two different objects, i1 and i2 are just references and these two holds same value 10, == operator is used to check the reference is same or not and .equals is used to check content is same or not. Here both content and reference is same so ans is C

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. Class F
{
Static long test(int i){
Return I;
}
Public static void main(String args[]){
Short s=10;
Double d2=test(s);
System.out.println(d2);
}
}
A. compile time error B. runtime error
C. 10.0 D. 0

Answer and Explanation

Answer: 10.0

Explanation:
from main() we are calling test() by passing 10, but it returns of type long , that long value can be stored in double variable d2, so output is 10.0

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Class F
{
Static void test(Long i){
System.out.println(“long”);
}
Public static void main(String args[]){
byte s=10;
test(s);
}
}
A. compile time error B. runtime error
C. long D. 0

Answer and Explanation

Answer: compile time error

Explanation:
Here byte is a primitive type variable and we are trying to store in Long which is of type class ,so it will throw compile time error

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. Class F
{
Static void test(long i){
System.out.println(“long”);
}
Public static void main(String args[]){
byte s=10;
test(s);
}
}
A. compile time error B. runtime error
C. long D. 0

Answer and Explanation

Answer: long

Explanation:
Here byte is a primitive type variable and we are trying to store in long which is also of type primitive, so it will not throw any error, so ans is C

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.